package com.wwz.leetcode;

import java.util.HashMap;
import java.util.Map;

public class LeetCode {

    public static void main(String[] args) {
        int [][] arr = {{1,1,0,1},{1,0,1,0},{1,1,1,1}};
        setZeroes(arr);
    }
    /**
     * @Description: 编写一种算法，若M × N矩阵中某个元素为0，则将其所在的行与列清零。
     * @create: 2020-06-02 15:11
     * @update logs
     * @throws Exception
     */
    public static void setZeroes(int[][] matrix) {
        int lenx = matrix.length;  //行
        int leny = matrix[0].length;  //列
        boolean[] row = new boolean[lenx], col = new boolean[leny];
        for (int i = 0; i < lenx; i++)
            for (int j = 0; j < leny; j++)
                if (matrix[i][j] == 0) {
                    row[i] = true;
                    col[j] = true;
                }
        for (int i = 0; i < lenx; i++)
            for (int j = 0; j < leny; j++)
                if (row[i] || col[j])
                    matrix[i][j] = 0;
        for (int[] is : matrix) {
            for (int i : is) {
                System.out.print(i + ",");
            }
            System.out.print("\n");

        }
    }

    public static boolean isUnique(String astr) {
        char[] array = astr.toCharArray();
        Boolean bool = true;
        for (int i = 0; i <array.length ; i++) {
            for(int k = array.length-1; k>=0 ; k--)
                if(i != k && array[i]==array[k]){
                    bool=false;
                }
            if(bool==false){
                System.out.println("提前返回"+bool);
                return bool;
            }
        }
        System.out.println(bool);
        return bool;
    }
    public static boolean isUnique2(String astr) {
        char[] array = astr.toCharArray();
        Boolean bool = true;
        Map<String,Object> map = new HashMap<String,Object>();
        for(char a:array){
            if(map.get(String.valueOf(a))!=null){
                map.put(String.valueOf(a),Integer.parseInt(map.get(String.valueOf(a)).toString())+1);
            }else {
                map.put(String.valueOf(a), 1);
            }
            if(Integer.parseInt(map.get(String.valueOf(a)).toString())>=2){

                System.out.println(false);
                return false;
            }

        }
        System.out.println(bool);
        return bool;
    }
}
